package licode.unisop.client.service.filter;

import licode.unisop.client.utils.SopException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author licode
 */
@Slf4j
public class SopAuthorizationInterceptor implements HandlerInterceptor {
    private final SopAuthorizationHandler handler;

    public SopAuthorizationInterceptor(SopAuthorizationHandler handler) {
        this.handler = handler;
    }

    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object objHandler) throws Exception {
        SopException exception = this.handler.doHandle(request, response);
        if (null != exception) {
            throw exception;
        }
        return true;
    }
}
